/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package astroim.smack;

import astroim.AstroIMMessaging;
import java.util.HashMap;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManagerListener;

/**
 *
 * @author alykhalid
 */
public class CustomChatListener implements ChatManagerListener{
    private HashMap<String, AstroIMMessaging> chatters = new HashMap<String, AstroIMMessaging>();

    public HashMap<String, AstroIMMessaging> getChatters() {
        return chatters;
    }

    public void chatCreated(Chat chat, boolean bln) {
        String JID = chat.getParticipant();
        if(!chatters.containsKey(JID)){
            AstroIMMessaging aimm = new AstroIMMessaging();
            chat.addMessageListener(aimm);
            chatters.put(JID, aimm);
        }
        else {
            chat.addMessageListener(chatters.get(JID));
        }
    }

    public String NormalizeJID(String JID){
        return JID.split("/")[0];
    }

    public static CustomChatListener getInstance() {
        return CustomChatListenerHolder.INSTANCE;
    }

    private static class CustomChatListenerHolder {
        private static final CustomChatListener INSTANCE = new CustomChatListener();
    }


}
